What is multiple definition?

Multiple definition occurs when a program contains more than one definition of a symbol, such as a variable, function, or class. This can result in conflicts and error messages during compilation, as the compiler cannot determine which definition to use.

Multiple definition can occur when two or more source files define the same global variable or function. This can happen if the same header file is included in multiple source files. It can also occur if the same source file is included in multiple translation units.

To avoid multiple definition errors, it is important to ensure that each symbol has only one definition in the program. This can be achieved by using the proper naming conventions, avoiding global variables, and using header guards. In C++, it is possible to use the extern keyword to declare a symbol without defining it. This allows the symbol to be defined in a single source file and used by other files without causing multiple definition errors.